import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    myLike: [],
    myCollection: [],
    myFootsteps: [],
  },
  getters: {
  },
  mutations: {
    toggleMyLike(state, data) {
      let { id } = data
      if (!state.myLike.length) {
        state.myLike.push(data)
      } else {
        let index = state.myLike.findIndex((item) => item.id == id)
        if (index == -1) {
          state.myLike.push(data)
        } else {
          state.myLike.forEach((m, i) => {
            if (m.id === id) {
              state.myLike.splice(i, 1)
            }
          })
        }
      }
    },
    toggleMyCollection(state, data) {
      let { id } = data
      if (!state.myCollection.length) {
        state.myCollection.push(data)
      } else {
        let index = state.myCollection.findIndex((item) => item.id == id)
        if (index == -1) {
          state.myCollection.push(data)
        } else {
          state.myCollection.forEach((m, i) => {
            if (m.id === id) {
              state.myCollection.splice(i, 1)
            }
          })
        }
      }
    },
    toggleMyFootsteps(state, data) {
      let { id } = data
      if (!state.myFootsteps.length) {
        state.myFootsteps.push(data)
      } else {
        let index = state.myFootsteps.findIndex((item) => item.id == id)
        if (index == -1) {
          state.myFootsteps.push(data)
        } else {
          state.myFootsteps.forEach((m, i) => {
            if (m.id === id) {
              state.myFootsteps.splice(i, 1)
            }
          })
        }
      }
    }
  },
  actions: {
  },
  modules: {
  }
})
